import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

//ts写法有点难受
import {layout} from '@/layout/constant'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name:'Home',
    meta:{
      title:'首页'
    },
    component: () => import('@/views/Home.vue'),
  },
  {
    path: '/login',
    name:'login',
    meta:{
      title:'登录页'
    },
    component: () => import('@/views/login/index.vue'),
  },
  {
    path: '/',
    component: layout,
    children:[
      {
        path: 'console2',
        meta:{
          title:'商品页2'
        },
        component: () => import('@/views/dashboard/console2.vue'),
      },
      {
        path: 'console',
        name:'console',
        meta:{
          title:'商品页'
        },
        component: () => import('@/views/dashboard/console.vue'),
      },
      {
        path: 'cs',
        name:'cs',
        meta:{
          title:'测试1'
        },
        component: () => import('@/views/cs/cs1.vue'),
      },
      {
        path: `cs/:id`,
        name:'cs2',
        props:true,
        meta:{
          title:'测试2'
        },
        component: () => import('@/views/cs/cs2.vue'),
      },
      {
        path: 'cs/:id/:bid',
        name:'cs3',
        props:true,
        meta:{
          title:'测试3'
        },
        component: () => import('@/views/cs/cs3.vue'),
      },
    ]
  },




]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
//前置导航守卫(跳转页面之前)
router.beforeEach(function (to,fom,next){
console.log(to.meta.title)
  //ts小知识不用管(页名称)
 document.title =(to?.meta?.title as string)
  //预设一个进度条可以不用管
  // setTimeout(()=>{
  //   // ProgressBar.start()
   next()
  // },500)

})
//后置导航守卫(跳转页面之后)
router.afterEach(function (to,from){
     // ProgressBar.finish()
})

export default router
